const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    status:true,
    order:{},
    customerId:'',
    recordId:11
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    let t = this,customerId = wx.getStorageSync('customerId');
    if(customerId){
      t.setData({recordId:e.recordId,app:app},t.init)
    }else {
      getApp().page.onLoad(t, e);
      app.bus.onLoad(t);
    }

  },
  init(){
    let t = this,d = t.data;
    wx.request({
      url:'https://live.sgwxmini.com/beauty/wxQuickBill/wxSaveTrans',
      data:{
        hosId: app.api.siteinfo.hosId,
        recordId:d.recordId,
        mobile:wx.getStorageSync('appUserInfo').mobile
      },
      success(e){
        t.setData({order:e.data.data})
      }
    })
  },

  pay(){
    let t=this, d = t.data;
    wx.showLoading({mask:true})
    wx.request({
      url:'https://live.sgwxmini.com/beauty/wxPay/quickBillPlaceOrder',
      data:{
        hosId:app.api.siteinfo.hosId,
        transId:d.order.orderId,
        mobile:wx.getStorageSync('appUserInfo').mobile,
        type:1
      },
      success(e){
        console.log(e)
        wx.requestPayment({
          ...e.data.data,
          success(e) {
            wx.showToast({title:'支付成功'})
            t.setData({status:false})
          },
          fail(err){
            wx.showToast({icon:'none',title:'支付失败'})
          },
          complete:wx.hideLoading
        })
      }
    })
  },
})